<script type="text/javascript" src="{{$LAYOUT_HELPER_URL}}admin/js/ckeditor/ckeditor.js"></script> 
<script type="text/javascript" src="{{$LAYOUT_HELPER_URL}}admin/js/ckfinder/ckfinder.js"></script>  
<link href="{{$LAYOUT_HELPER_URL}}admin/js/jquery-ui/css/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="{{$LAYOUT_HELPER_URL}}admin/js/jquery-ui/js/jquery-ui.js"></script>
<script src="{{$LAYOUT_HELPER_URL}}admin/js/jquery.slug.js"></script>
<!-- Bootstrap -->

<script src="{{$LAYOUT_HELPER_URL}}admin/js/jquery.tmpl.min.js"></script>

<script id="choiceTemplate" type="text/x-jquery-tmpl">
    <li>
        <div class="control-group">
            <label class="control-label" for="inputChoice1" style="min-width:50px;padding-left:140px;">
                <input type="checkbox" class="checkAns_${lang}" onclick="countCheck()" name="data2[${lang}][check][]" value="b"></label>
            <div class="controls">
                <div class="input-prepend input-append">
                    <span class="add-on">${c}</span>
                    <input class="span3" name="data2[${lang}][answer][]" id="Text2" type="text">
                    <button class="btn btnRemoveChoice"><i class="icon-remove"></i></button>
                </div>
            </div>
        </div>
    </li>
</script>

<script src="{{$LAYOUT_HELPER_URL}}admin/js/bootstrap.file-input.js"></script>
<script src="{{$LAYOUT_HELPER_URL}}admin/js/init.js"></script>

<link href="{{$LAYOUT_HELPER_URL}}admin/css/bootstrap.css" rel="stylesheet" media="screen">
<link href="{{$LAYOUT_HELPER_URL}}admin/css/style2.css" rel="stylesheet" />
<!--                       CSS                       -->

<link rel="stylesheet" href="{{$LAYOUT_HELPER_URL}}admin/css/reset.css"  type="text/css"  />

<link rel="stylesheet" href="{{$LAYOUT_HELPER_URL}}admin/css/style.css" type="text/css" />

<link rel="stylesheet" href="{{$LAYOUT_HELPER_URL}}admin/css/invalid.css"  type="text/css" /> 
<style>
    h1, h2, h3 {
        line-height: 30px;
    }
    li {
        line-height: 12px;
    }
    .ui-autocomplete {
        max-height: 200px;
        overflow-y: auto;
        /* prevent horizontal scrollbar */
        overflow-x: hidden;
        /* add padding to account for vertical scrollbar */
        padding-right: 20px;
    }
    /* IE 6 doesn't support max-height
     * we use height instead, but this forces the menu to always be this tall
    */
    * html .ui-autocomplete {
        height: 100px;
    }

</style>


<script type="text/javascript">

    function countCheck(lang_id)
{
		
    var x = [];
    $('.checkAns_' + lang_id).each(function(){
    if($(this).is(":checked"))
                {
                        x.push(1);
                }
                else x.push(0);
            });
            $('input#checkboxAns_' + lang_id).val(x);
        }

        function submitQuestion()
{
countCheck(1);
countCheck(2);
$('#submitFormQuestion').submit();
	
}
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}

function addInput()
{
var value = $(".ui-corner-right ui-button-icon").val();
     
jQuery.ajax({
url: '{{$APP_BASE_URL}}product/admin/add-input',
type: "POST",
data: {'value':value},
beforeSend: function( xhr ) {
},
success: function( data ) {
//Do anything
//  alert(data);
appendOptionLast(data,value);
}
});
}

//<![CDATA[

jQuery(document).ready(function (){

        
CKFinder.setupCKEditor( null, '{{$LAYOUT_HELPER_URL}}admin/js/ckfinder/' );
jQuery( "#images" ).sortable();
jQuery( "#images" ).disableSelection();
//Datepicker
jQuery( ".date" ).datepicker({
showAnim        : 'slideDown',
showButtonPanel : true,
dateFormat      : '{{$datepickerFormat.js}}'
});

//Make slug
    {{foreach from=$allLangs item=item name=langDiv}}
jQuery('#title').makeSlug({
slug: jQuery('#alias')
});
    {{/foreach}}
       	 
 	                         
$( "#unit" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
availableUnit, extractLast( request.term ) ) );
},
focus: function() {
// prevent value inserted on focus
return false;
},
 	                
});   

var availableUnit = new Array();
  	       
    {{foreach from=$allUnits item=item key=k}}
availableUnit[{{$k}}] = "{{$item.name}}";
    {{/foreach}} 

  	  	    	
        
});
    
function showMenu() {
$("#unit").autocomplete( "search" , '' );
}
function appendOptionLast(num,value)
    {
var elOptNew = document.createElement('option');
elOptNew.text =  value;
elOptNew.value =  num;
var elSel = document.getElementById('combobox');

try {
elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
}
catch(ex) {
elSel.add(elOptNew); // IE only
}
}
//]]>
</script>
<style type="text/css">
    #images { list-style-type: none; margin: 0; padding: 0;}
    #images li { margin: 10px; float: left; text-align: center;  height: 180px;}
</style>



<div class="content-box"><!-- Start Content Box -->

    <div class="content-box-header">

        <h3>Edit Question</h3>

        <ul class="content-box-tabs">
            {{if $fullPermisison}}<li><a href="#tab0" class="default-tab">General</a></li>{{/if}}
            {{foreach from=$allLangs item=item index=index name=langTab}}
            <li><a {{if !$fullPermisison && $smarty.foreach.langTab.first}}class="default-tab"{{/if}} href="#tab{{$item.lang_id}}" style="padding-bottom: 4px;"><image style="vertical-align:middle;" src="{{$BASE_URL}}{{$item.lang_image}}"> {{$item.name}}</a></li>
            {{/foreach}}
        </ul>

        <div class="clear"></div>

    </div> <!-- End .content-box-header -->

    <div class="content-box-content">

        <form id="submitFormQuestion" action="" method="post">

            <!-- GENERAL -->
            <div class="tab-content {{if !$fullPermisison}}hidden{{/if}}" id="tab0">

                <!-- ERROR -->
                {{if $errors|@count > 0}}
                <div class="notification error png_bg">
                    <a href="#" class="close"><img src="{{$LAYOUT_HELPER_URL}}admin/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
                    <div>
                        {{if $errors.main}}
                        Error: {{$errors.main}}
                        {{else}}
                        Error: Please check following information again
                        {{/if}} 

                    </div>
                </div>
                {{/if}}

                <fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
                    <p>
                        <label>Category<span class="red">*</span></label>              
                        <select name="data[content_category_gid]" class="small-input">
                            {{foreach from=$allCats item=item}}
                            <option value="{{$item.content_category_gid}}" {{if $data.content_category_gid == $item.content_category_gid}}selected="selected"{{/if}}>{{$item.name}}</option>
                            {{/foreach}}
                        </select> 
                    </p>
                    <p>
                        <label>Published<span class="red">*</span></label>
                        <input type="radio" name="data[genabled]" value="1" {{if $data.genabled != '0'}}checked="checked"{{/if}}/> Yes &nbsp;&nbsp;&nbsp;&nbsp;
                               <input type="radio" name="data[genabled]" value="0" {{if $data.genabled == '0'}}checked="checked"{{/if}}/> No
                    </p>
                    <p>
                        <label>Sorting<span class="red">*</span><br/><br/></label>
                        <input class="text-input small-input" type="text"  name="data[sorting]" value="{{$data.sorting}}" />{{if $errors.repeat_password}}<span class="input-notification error png_bg"></span>{{/if}}
                        <br /><small>No 1 will display as first article</small>
                    </p>
                    <p>
                        <label>Type<span class="red">*</span></label>
                        <input type="radio" name="data[type]" value="1" {{if $data.type == '1'}}checked="checked"{{/if}}/> Lecture &nbsp;&nbsp;&nbsp;&nbsp;
                               <input type="radio" name="data[type]" value="0" {{if $data.type == '0'}}checked="checked"{{/if}}/> Exercise
                    </p>



                    <br/>
                    <div>
                        <label>Level</label>


                        <div class="ui-widget" style="width: 180px;float: left ;height: 30px;">

                            <input class="small-input"  style="width:100px;" id="unit" name="data[level]" value="{{$data.level}}"> 
                            <button aria-disabled="false" role="button" class="ui-button ui-widget ui-state-default ui-button-icon-only ui-corner-right ui-button-icon" title="Show All Items" tabindex="-1" style="margin-left:-10px;" onclick="showMenu();" type="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text">&nbsp;</span></button>

                        </div>
                    </div>
                    <br/>










                    <p>
                        <br/>
                        <input class="button submit" type="button" value="Save" />
                    </p>

                </fieldset>


                <div class="clear"></div><!-- End .clear -->

            </div>  <!-- End GENERAL --> 

            {{foreach from=$allLangs item=item name=langDiv}}
            <!-- LANGUAGES -->
            <div class="tab-content {{if $fullPermisison || !$smarty.foreach.langDiv.first}}hidden{{/if}}" id="tab{{$item.lang_id}}">

                <fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
                    <p>
                        <label>Published</label>
                        <input type="radio" name="data[{{$item.lang_id}}][enabled]" value="1" {{if $data[$item.lang_id].enabled == '1'}}checked="checked"{{/if}}/> Yes &nbsp;&nbsp;&nbsp;&nbsp;
                               <input type="radio" name="data[{{$item.lang_id}}][enabled]" value="0" {{if $data[$item.lang_id].enabled != '1'}}checked="checked"{{/if}}/> No
                    </p>
                    <p>
                        <label>Title</label>
                        <input id="title{{$smarty.foreach.langDiv.iteration}}" class="text-input large-input" type="text"  name="data[{{$item.lang_id}}][title]" value="{{$data[$item.lang_id].title}}" />
                    </p>
                        <input id="alias{{$smarty.foreach.langDiv.iteration}}" style="width: 675px;display:none" class="text-input small-input" type="text"  name="data[{{$item.lang_id}}][alias]" value="{{$data[$item.lang_id].alias}}" /> 

                    <div><textarea style="float:left;" class="text-input textarea ckeditor"  name="data[{{$item.lang_id}}][full_text]" rows="20" cols="90">{{$data[$item.lang_id].full_text}}</textarea></div>
                    <div class="row" style="padding-left:20px;">
                        <fieldset>



                            <div class="toggleContent">
                                <h5>Answers:</h5>
                                {{if $data[$item.lang_id].answer|@count > 0}}

                                <ul class="multichoice_{{$item.lang_id}} nav">

                                    {{foreach from=$data[$item.lang_id].answer item=item2 name=ans}}
                                    {{if $smarty.foreach.ans.last}}
                                    <li>             
                                        <div class="control-group"> 
                                            <label style="min-width:50px;padding-left:140px;" for="inputChoice1" class="control-label"> 
                                                <input type="checkbox" class="checkAns_{{$item.lang_id}}" onclick="countCheck({{$item.lang_id}})" {{if ($item.is_true == 1)}}checked="checked" {{/if}} name="data2[{{$item.lang_id}}][check][]" value="a"></label> 
                                            <div class="controls"> 
                                                <div class="input-prepend input-append">
                                                    <span class="add-on">B</span> 
                                                    <input type="text" id="Text2" name="data2[{{$item.lang_id}}][answer][]" value="{{$item2.content}}" class="span3">
                                                    <button class="btn btnAddChoice" value="{{$item.lang_id}}"><i class="icon-plus"></i></button>                   
                                                </div>
                                                <!--                                                    <div class="dialogAns">
                                                                                                        <textarea style="" class="text-input textarea ckeditor"  name="data[{{$item.lang_id}}][full_text_1]" rows="20" cols="90">{{$data[$item.lang_id].full_text}}</textarea>
                                                                                                    </div>-->
                                            </div>             
                                        </div>         
                                    </li>
                                    {{else}}



                                    <li>             
                                        <div class="control-group"> 
                                            <label style="min-width:50px;padding-left:140px;" for="inputChoice1" class="control-label"> 
                                                <input type="checkbox" class="checkAns_{{$item.lang_id}}" onclick="countCheck({{$item.lang_id}})" {{if ($item2.is_true == 1)}}checked="checked" {{/if}} name="data2[{{$item.lang_id}}][check][]" value="a" /></label> 
                                            <div class="controls"> 
                                                <div class="input-prepend input-append">
                                                    <span class="add-on">A</span> 
                                                    <input type="text" id="Text2" name="data2[{{$item.lang_id}}][answer][]" value="{{$item2.content}}" class="span3">
                                                    <button class="btn btnRemoveChoice"><i class="icon-remove"></i></button>                     
                                                </div>
                                                <!--                                                    <div class="dialogAns">
                                                                                                        <textarea style="" class="text-input textarea ckeditor"  name="data[{{$item.lang_id}}][full_text_1]" rows="20" cols="90">{{$data[$item.lang_id].full_text}}</textarea>
                                                                                                    </div>-->
                                            </div>             
                                        </div>         
                                    </li>
                                    {{/if}}
                                    {{/foreach}}

                                </ul>
                                {{else}}
                                <ul class="multichoice_{{$item.lang_id}} nav">
                                    <li>             
                                        <div class="control-group"> 
                                            <label style="min-width:50px;padding-left:140px;" for="inputChoice1" class="control-label"> 
                                                <input type="checkbox" class="checkAns_{{$item.lang_id}}" onclick="countCheck({{$item.lang_id}})" name="data2[{{$item.lang_id}}][check][]" value="a"></label> 
                                            <div class="controls"> 
                                                <div class="input-prepend input-append">
                                                    <span class="add-on">A</span> 
                                                    <input type="text" id="Text2" name="data2[{{$item.lang_id}}][answer][]" class="span3">
                                                    <button class="btn btnRemoveChoice"><i class="icon-remove"></i></button>                     </div>                 </div>             </div>         </li>
                                    <li>
                                        <div class="control-group">
                                            <label class="control-label" for="inputChoice1" style="min-width:50px;padding-left:140px;">
                                                <input type="checkbox" class="checkAns_{{$item.lang_id}}" onclick="countCheck({{$item.lang_id}})" name="data2[{{$item.lang_id}}][check][]" value="b"></label></label>
                                            <div class="controls">
                                                <div class="input-prepend input-append">
                                                    <span class="add-on">B</span>
                                                    <input class="span3" name="data2[{{$item.lang_id}}][answer][]" id="inputChoice" type="text">
                                                    <button class="btn btnAddChoice" value="{{$item.lang_id}}"><i class="icon-plus"></i></button>
                                                </div>
                                            </div>
                                        </div></li>
                                </ul>

                                {{/if}}
                            </div>

                        </fieldset>
                    </div>

                    <input type="hidden" name="data2[{{$item.lang_id}}][checkAns]" id="checkboxAns_{{$item.lang_id}}" />   
                    <p>
                        <br/>
                        <input class="button submit" type="button" value="Save" />
                    </p>

                </fieldset>

                <div class="clear"></div><!-- End .clear -->

            </div>


            {{/foreach}}

        </form>

    </div> <!-- End .content-box-content -->

</div> <!-- End .content-box -->


<div class="clear"></div>